#include <stdio.h>
#include <memory.h>


/*
 * memory search
 */
char *simple_memchr (const char *s, int c, size_t n)
{
  while (n--)
    if (*s++ == (char) c)
      return (char *) s - 1;
  return NULL;
}

int  ch = 'b';
char str[] =    "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] =   "         1         2         3         4         5";
char fmt2[] =   "12345678901234567890123456789012345678901234567890";

static void _main( void )
{
	char *pdest;
	int result;
	printf( "String to be searched:\n\t\t%s\n", string );
	printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
	
	printf( "Search char:\t%c\n", ch );
	pdest = simple_memchr( string, ch, sizeof( string ) );
	result = pdest - string + 1;
	if( pdest != NULL )
		printf( "Result:\t\t%c found at position %d\n\n", ch, result );
	else
		printf( "Result:\t\t%c not found\n" );
}
